package org.example.platform.design.simplefactory.version1;


import java.util.Arrays;

/**
 * 简单工厂   第1版
 */
public class Factory {

    final String[] fhs = new String[]{"+","-","*","/"};


    /** 第1版
     * 输入两个数字，一个运算符，得出结果
     * @param num
     * @param num2
     * @param fh
     */
    public void inputNum(Integer num,Integer num2,String fh) throws Exception {
        if(null == num){
            throw new Exception("输入的第一位数字不能为空！");
        }
        if(null == num2){
            throw new Exception("输入的第二位数字不能为空！");
        }
        if(null == fh || "".equals(fh)){
            throw new Exception("输入的符号不能为空！");
        }else if(!Arrays.asList(fhs).contains(fh)){
            throw new Exception("输入的符号不正确！正确符号为+-*/");
        }

        double result = 0;
        switch (fh){
            case "*":
                result = num*num2;
                break;
            case "-":
                result = num-num2;
                break;
            case "/":
                if(num == 0){
                    throw new Exception("除数不能为0！");
                }
                result = num/num2;
                break;
            case "+":
                result = num+num2;
                break;
        }
        System.out.println(result);
    }

    public static void main(String[] args) {
        int num=6;
        int num2=7;
        String fh="*";
        double result = 0;
        switch (fh){
            case "*":
                result = num*num2;
                break;
            case "-":
                result = num-num2;
                break;
            case "/":
                result = num/num2;
                break;
            case "+":
                result = num+num2;
                break;
        }
        System.out.println(result);
    }
}
